var currentPage = 1;
var pageSize = 10;
var totalCount = 0;
var totalPage = 1;

function showPage() {
    if (totalPage==0){
        totalPage=1;
    }
    if (currentPage<1){
        currentPage=1
    }
    $("#showPage").text(currentPage+"/"+totalPage);
}

function showInfo() {
    let name = $("#name").val().trim();
    let positionName = $("#positionName").val().trim();
    let experience = $("#experience").val().trim();
    let status = $("#status").val().trim();
    let rTime = $("#rTime").val().trim();

    $("#tal1").find("tr:gt(0)").find("td").html("&nbsp;");

    let jsonA={
        name:name,
        positionName:positionName,
        experience:experience,
        status:status,
        rTime:rTime,
        currentPage:currentPage,
        pageSize:pageSize
    }

    $.ajaxSettings.async=false;
    $.getJSON("showMianShi",jsonA,function(data){
        totalCount=data.total;
        totalPage=data.pages;
        $(data.list).each(function (i,v) {
            let xiala;
            let tiao="<button type=\"button\" class=\"layui-btn\"  onclick=\"messageById("+v.resumeId+")\">录用结果登记</button>&nbsp;&nbsp;<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"shanchu("+v.resumeId+",this)\">删除</button>";
            if (v.status=="存档"){
                xiala="<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='"+v.interviewId+"' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"存档\" selected='selected' disabled='disabled'>存档</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao="<button type=\"button\" class=\"layui-btn\"  onclick=\"messageById("+v.resumeId+")\">明细</button>&nbsp;&nbsp;<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"shanchu("+v.resumeId+",this)\">删除</button>";
            }
            if (v.status=="推荐面试"){
                xiala="<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='"+v.interviewId+"' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"录用\" disabled='disabled'>录用</option>\n" +
                    "<option value=\"删除\" disabled='disabled'>删除</option>\n" +
                    "<option value=\"存档\" disabled='disabled'>存档</option>\n" +
                    "<option value=\"推荐面试\" selected='selected' disabled='disabled'>推荐面试</option>\n" +
                    "<option value=\"推荐二面\" disabled='disabled'>推荐二面</option>\n" +
                    "<option value=\"推荐三面\" disabled='disabled'>推荐三面</option>\n" +
                    "<option value=\"建议录用\" disabled='disabled'>建议录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao="<button type=\"button\" class=\"layui-btn\"  onclick=\"messageById("+v.resumeId+")\">明细</button>&nbsp;&nbsp;<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"shanchu("+v.resumeId+",this)\">删除</button>";
            }
            if (v.status=="推荐二面"){
                xiala="<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='"+v.interviewId+"' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"推荐面试\" disabled='disabled'>推荐面试</option>\n" +
                    "<option value=\"推荐二面\" selected='selected' disabled='disabled'>推荐二面</option>\n" +
                    "<option value=\"推荐三面\" disabled='disabled'>推荐三面</option>\n" +
                    "<option value=\"建议录用\" disabled='disabled'>建议录用</option>\n" +
                    "<option value=\"录用\" disabled='disabled'>录用</option>\n" +
                    "<option value=\"存档\" disabled='disabled'>存档</option>\n" +
                    "<option value=\"删除\" disabled='disabled'>删除</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao="<button type=\"button\" class=\"layui-btn\"  onclick=\"messageById("+v.resumeId+")\">明细</button>&nbsp;&nbsp;<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"shanchu("+v.resumeId+",this)\">删除</button>";
            }
            if (v.status=="推荐三面"){
                xiala="<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px; \">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='"+v.interviewId+"' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"推荐面试\" disabled='disabled'>推荐面试</option>\n" +
                    "<option value=\"推荐二面\" disabled='disabled'>推荐二面</option>\n" +
                    "<option value=\"推荐三面\" selected='selected' disabled='disabled'>推荐三面</option>\n" +
                    "<option value=\"建议录用\" disabled='disabled'>建议录用</option>\n" +
                    "<option value=\"录用\" disabled='disabled'>录用</option>\n" +
                    "<option value=\"存档\" disabled='disabled'>存档</option>\n" +
                    "<option value=\"删除\" disabled='disabled'>删除</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao="<button type=\"button\" class=\"layui-btn\"  onclick=\"messageById("+v.resumeId+")\">明细</button>&nbsp;&nbsp;<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"shanchu("+v.resumeId+",this)\">删除</button>";
            }
            if (v.status=="建议录用"){
                xiala="<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='"+v.interviewId+"' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"录用\">录用</option>\n" +
                    "<option value=\"存档\">存档</option>\n" +
                    "<option value=\"删除\">删除</option>\n" +
                    "<option value=\"推荐面试\" disabled='disabled'>推荐面试</option>\n" +
                    "<option value=\"推荐二面\" disabled='disabled'>推荐二面</option>\n" +
                    "<option value=\"推荐三面\" disabled='disabled'>推荐三面</option>\n" +
                    "<option value=\"建议录用\" selected='selected' disabled='disabled'>建议录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
            }
            if (v.status=="录用"){
                xiala="<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='"+v.interviewId+"' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"录用\" selected='selected' disabled='disabled'>录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao="<button type=\"button\" class=\"layui-btn\"  onclick=\"messageById("+v.resumeId+")\">明细</button>&nbsp;&nbsp;<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"shanchu("+v.resumeId+",this)\">删除</button>";
            }
            if (v.status=="删除"){
                xiala="<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='"+v.interviewId+"' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"删除\" selected='selected' disabled='disabled'>删除</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao="<button type=\"button\" class=\"layui-btn\"  onclick=\"messageById("+v.resumeId+")\">明细</button>&nbsp;&nbsp;";
            }
            $("#tal1").find("tr").eq(i+1).find("td").eq(0).text((currentPage-1)*pageSize+1+i);
            $("#tal1").find("tr").eq(i+1).find("td").eq(1).text(v.name);
            $("#tal1").find("tr").eq(i+1).find("td").eq(2).text(v.sex);
            $("#tal1").find("tr").eq(i+1).find("td").eq(3).text(v.school);
            $("#tal1").find("tr").eq(i+1).find("td").eq(4).text(v.educationBackground);
            $("#tal1").find("tr").eq(i+1).find("td").eq(5).text(v.major);
            $("#tal1").find("tr").eq(i+1).find("td").eq(6).text(v.positionName);
            $("#tal1").find("tr").eq(i+1).find("td").eq(7).text(v.experience);
            $("#tal1").find("tr").eq(i+1).find("td").eq(8).text(v.rTime);
            $("#tal1").find("tr").eq(i+1).find("td").eq(9).html(xiala);
            $("#tal1").find("tr").eq(i+1).find("td").eq(10).html(tiao);
        })

    })
    $.ajaxSettings.async=true;
    showPage();
    layui.use('form', function() {
        var form = layui.form;
        form.render();
    });
}
function check() {
    showInfo();
}

function next() {
    currentPage++;
    if(currentPage>totalPage){
        currentPage=totalPage;
        return;
    }
    showInfo()
}

function prev() {
    currentPage--;
    if(currentPage<1){
        currentPage=1;
        return;
    }
    showInfo()
}

function first() {
    currentPage=1;
    showInfo()
}

function end() {
    currentPage=totalPage;
    showInfo()
}

function messageById(rId) {
    window.location.href = "/录用结果登记/" + rId;
}
function shanchu(rId,thisA) {

    layer.confirm('确定要删除吗?', {icon: 3, title:'提示'}, function(){
        let jsonA={
            interviewId:rId,
            status:"删除"
        }
        $.ajaxSettings.async = false;
        $.post("/save22", jsonA, function (dataA) {
            if (dataA > 0) {
                $(thisA).parents("tr").remove();
                layer.closeAll();
            } else {
                alert("删除失败！");
                return;
            }
        },"JSON")
        $.ajaxSettings.async = true;
        if (totalCount%pageSize==0){
            currentPage=currentPage-1;
        }
        showPage();
        showInfo();
        layer.close();
    });
    showInfo();
}


layui.use('form', function() {
    let form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

    let time;
    form.on('select(stat1)', function (data) {
        abc = (data.value);

        let id = $(this).parent().parent().parent().find("option").eq(0).val()
        if(abc=="录用"){
            layer.open({
                title: '录用登记'
                ,content: '<table class="layui-table myTable3">\n' +
                    '        <tr>\n' +
                    '            <td>决议时间：</td>\n' +
                    '            <td><input type="text" class="layui-input endTime" value="" readonly="readonly"></td>\n' +
                    '            <td colspan="2"></td>\n' +
                    '        <tr>\n' +
                    '            <td width="20%">录用决议：</td>\n' +
                    '            <td colspan="3"> <textarea class="layui-input endOpinion" name="endOpinion"></textarea></td>\n' +
                    '        </tr>\n' +
                    '    </table>',
                area: ['600px', '300px'],
                btn:["确定","取消"],
                success:function(){//弹出层弹出后回调
                    //当前日期赋值给时间
                    time = new Date().toLocaleDateString();
                    $(".endTime").val(time);

                    //取消esc
                    $('.layui-layer-setwin').hide();
                },
                btn1:function(){//确定事件

                    let endOpinion = $(".endOpinion").val().trim();

                    let jsonA={
                        interviewId:id,
                        status:abc,
                        endTime:time,
                        endOpinion:endOpinion
                    }

                    $.ajaxSettings.async = false;
                    $.post("/save21", jsonA, function (dataA) {
                        if (dataA > 0) {
                            layer.closeAll();
                        } else {
                            alert("结果登记失败！");
                            return;
                        }
                    },"JSON")
                    showInfo();
                    $.ajaxSettings.async = true;
                },
                btn2:function(){//取消事件
                    showInfo();
                }
            });
        }else if(abc=="存档"){

            layer.confirm('确定要存档吗?', {icon: 3, title:'提示'}, function(){
                let jsonA={
                    interviewId:id,
                    status:abc,
                    endTime:null,
                    endOpinion:null
                }

                $.ajaxSettings.async = false;
                $.post("/save21", jsonA, function (dataA) {
                    if (dataA > 0) {
                        layer.closeAll();
                    } else {
                        alert("存档失败！");
                        return;
                    }
                },"JSON")
                $.ajaxSettings.async = true;
                showInfo();
                layer.close();
            });
            showInfo();
        }else if(abc=="删除"){
            layer.confirm('确定要删除吗?', {icon: 3, title:'提示'}, function(){
                let jsonA={
                    interviewId:id,
                    status:abc
                }
                $.ajaxSettings.async = false;
                $.post("/save22", jsonA, function (dataA) {
                    if (dataA > 0) {
                        layer.closeAll();
                    } else {
                        alert("删除失败！");
                        return;
                    }
                },"JSON")

                if (totalCount%pageSize==0){
                    currentPage=currentPage-1;
                }
                showPage();
                showInfo();
                $.ajaxSettings.async = true;
                layer.close();
            });
            showInfo();
        }
    })
})